#include "WidgetVariantEnum.h"
#include "ui_WidgetVariantEnum.h"
#include <QtCore/QVariant>

WidgetVariantEnum::WidgetVariantEnum(QWidget *parent) :
    WidgetVariant(parent),
    ui(new Ui::WidgetVariantEnum)
{
    ui->setupUi(this);
}

WidgetVariantEnum::~WidgetVariantEnum()
{
    delete ui;
}

void WidgetVariantEnum::refreshByProperty(EItemMetaPropertyPtr p)
{
    // this->buildConnect();
    // WidgetVariant::refreshByProperty(p);
    
    // ui->labelName->setText( p->nameCN.isEmpty() ? p->name : p->nameCN);
    // [>
    // // QMetaEnum enumInfo = property.enumerator();
    // // 
    // for(int i = 0; i < property.enumNames.size(); i++)
    // {
        // ui->comboBox->addItem(property.enumNames[i]);
    // }
    // ui->comboBox->setCurrentIndex(property.value.toInt());
    // */
    // this->clearConnect();
}

void WidgetVariantEnum::buildConnect()
{
    QObject::connect(ui->comboBox, SIGNAL(currentIndexChanged(int )),
                     this, SLOT(slotCurrentIndexChanged(int)));
    QObject::connect(ui->comboBox, SIGNAL(currentTextChanged(const QString &)),
                     this, SLOT(slotCurrentTextChanged(const QString&)));
}

void WidgetVariantEnum::clearConnect()
{
    QObject::disconnect(ui->comboBox, SIGNAL(currentIndexChanged(int )),
                     this, SLOT(slotCurrentIndexChanged(int)));
    QObject::disconnect(ui->comboBox, SIGNAL(currentTextChanged(const QString &)),
                     this, SLOT(slotCurrentTextChanged(const QString&)));
}


void WidgetVariantEnum::performFilt()
{
    WidgetVariant::filtWidget(ui->comboBox->currentText());
}

    
void WidgetVariantEnum::slotCurrentIndexChanged(int index)
{
    QVariant v(index);
    // emit signalVariantChanged(WidgetVariant::getModuleName(), WidgetVariant::getProperty().name, v);
}

void WidgetVariantEnum::slotCurrentTextChanged(const QString &text)
{
    WidgetVariant::filtWidget(text);
}
